<!-- 广告汇总 -->
<template>
    <cl-crud ref="Crud">
        <cl-row>
            <!-- 刷新按钮 -->
            <cl-refresh-btn />
            <!-- 删除按钮 -->
            <cl-multi-delete-btn />
            <!-- 登录方式 -->
            <cl-filter label="创建时间">
                <cl-date-picker type="daterange" v-model="datePicker" />
            </cl-filter>
            <cl-flex1 />
            <!-- 关键字搜索 -->
            <cl-search-key placeholder="搜索昵称、手机号" />
        </cl-row>

        <cl-row>
            <!-- 数据表格 -->
            <cl-table ref="Table" show-summary :summary-method="onSummaryMethod" />
        </cl-row>

        <cl-row>
            <cl-flex1 />
            <!-- 分页控件 -->
            <cl-pagination />
        </cl-row>

        <!-- 新增、编辑 -->
        <cl-upsert ref="Upsert" />
    </cl-crud>
</template>

<script lang="ts" name="advertisingSummary" setup>
import { useCrud, useTable, useUpsert } from '@cool-vue/crud';
import { router, useCool } from '/@/cool';
import { reactive, ref } from 'vue';
import dayjs from 'dayjs';
const { service } = useCool();
// 数据选项
const options = reactive({
	loginType: [
		{
			label: '微信小程序',
			value: 0,
			type: 'info'
		},
		{
			label: '抖音小程序',
			value: 1
		},
		{
			label: 'H5',
			value: 2
		}
	],
	gender: [
		{
			label: '未知',
			value: 0,
			type: 'info'
		},
		{
			label: '男',
			value: 1,
			type: 'success'
		},
		{
			label: '女',
			value: 2,
			type: 'danger'
		}
	],
	adViewing: [
		{
			label: '开启',
			value: 0,
			type: 'success'
		},
		{
			label: '关闭',
			value: 1,
			type: 'danger'
		}
	],
	status: [
		{
			label: '禁用',
			value: 0,
			type: 'danger'
		},
		{
			label: '正常',
			value: 1,
			type: 'success'
		},
		{
			label: '已注销',
			value: 2,
			type: 'warning'
		}
	]
});
function onSummaryMethod() {
	return ['合计', '', '', 100 + ' 元'];
}
// cl-table
const Table = useTable({
	columns: [
		{
			type: 'selection',
			width: 60
		},
		{
			label: '昵称',
			prop: 'nickName',
			minWidth: 150
		},
		{
			label: '头像',
			prop: 'avatarUrl',
			minWidth: 100,
			component: {
				name: 'cl-avatar'
			}
		},
		{
			label: '登录方式',
			prop: 'loginType',
			dict: options.loginType
		},
		{
			label: '状态',
			prop: 'status',
			dict: options.status
		},
		{
			label: '广告权限',
			prop: 'adViewing',
			dict: options.adViewing
		},
		{
			label: '观看总数',
			prop: 'adCount'
		},
		{
			label: '观看时间',
			prop: 'adTime',
			minWidth: 150
		},
		{
			label: '创建时间',
			prop: 'createTime',
			sortable: 'desc',
			minWidth: 150
		}
	]
});
// cl-upsert
const Upsert = useUpsert({
	dialog: {
		width: '600px'
	},
	items: [
		{
			prop: 'avatarUrl',
			label: '头像',
			component: { name: 'cl-upload' }
		},
		{
			prop: 'nickName',
			label: '昵称',
			component: { name: 'el-input' },
			required: true
		},
		{
			prop: 'gender',
			label: '性别',
			value: 1,
			component: {
				name: 'el-radio-group',
				options: options.gender
			}
		},
		{
			prop: 'status',
			label: '状态',
			value: 1,
			component: {
				name: 'el-radio-group',
				options: options.status
			}
		},
		{
			prop: 'adViewing',
			label: '广告权限',
			value: 0,
			component: {
				name: 'el-radio-group',
				options: options.adViewing
			}
		}
	]
});
const datePicker = ref([
	dayjs().format('YYYY-MM-DD 00:00:00'),
	dayjs().add(1, 'days').format('YYYY-MM-DD 00:00:00')
]);
// cl-crud
const Crud = useCrud(
	{
		dict: {
			api: {
				page: 'getAdposGeneral'
			}
		},
		service: service.user.analysis
	},
	app => {
		app.refresh({
			start_date: dayjs().format('YYYY-MM-DD'),
			end_date: dayjs().add(1, 'days').format('YYYY-MM-DD')
		});
	}
);
</script>
